package com.bsoft.hospitalchs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bsoft.hospitalchs.R;
import com.bsoft.hospitalchs.model.ChildRecordList;

import java.util.List;

/**
 * Created by 泅渡者
 * Created on 2017/8/22.
 */

public class RecordListAdapter extends RecyclerView.Adapter<RecordListAdapter.ViewHolder> {
    private Context context;
    private List<ChildRecordList.BodyBean> dataList;

    public interface OnItemClickLitener {
        void onItemClick(View view, int potison);
    }

    private ChildCaseAdapter.OnItemClickLitener mOnItemClickLitener;

    public void setOnItemClickLitener(ChildCaseAdapter.OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;

    }


    public RecordListAdapter(Context context, List<ChildRecordList.BodyBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.recycle_record_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tv_age.setText(dataList.get(position).getAGE());
        holder.tv_time.setText(dataList.get(position).getVISITTIME());
        holder.tv_type.setText(dataList.get(position).getTYPE());
        holder.tv_jgmc.setText(dataList.get(position).getJGMC());
        if (mOnItemClickLitener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickLitener.onItemClick(holder.itemView, position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_age;
        private TextView tv_type;
        private TextView tv_time;
        private TextView tv_jgmc;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_age = (TextView) itemView.findViewById(R.id.tv_age);
            tv_type = (TextView) itemView.findViewById(R.id.tv_type);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
            tv_jgmc = (TextView) itemView.findViewById(R.id.tv_jgmc);

        }
    }

    public void addAllData(List<ChildRecordList.BodyBean> dataList) {
        for (ChildRecordList.BodyBean bodyBean : dataList) {
            this.dataList.add(bodyBean);
        }
        notifyDataSetChanged();
    }

    public void clearData() {
        this.dataList.clear();
        notifyDataSetChanged();
    }

    public ChildRecordList.BodyBean getCurrentItem(int position) {
        return dataList.get(position);
    }
}
